/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhnb
 * Date: 2011-8-9 上午10:25:22
 */
package box;

import java.io.Serializable;

import Ice.Communicator;

public class MyechoServer implements IceBox.Service, Serializable {

    private static final long serialVersionUID = 51387321327L;
    
    // 适配器对象。定义为成员，以保证start()与stop()一致。
    private Ice.ObjectAdapter objAdapter = null;

    /* (non-Javadoc)
     * @see IceBox.Service#start(java.lang.String, Ice.Communicator, java.lang.String[])
     */
    @Override
    public void start(String name, Communicator communicator, String[] args) {
        
        // Hello-${name}要与配置文件中保持一致。
        objAdapter = communicator.createObjectAdapter("Hello-" + name);
        
        // 配置文件中给定的K-V对
        String identity = communicator.getProperties().getProperty("Hello.Identity");
        
        // 添加服务进适配器
        objAdapter.add(new MyechoI(), communicator.stringToIdentity(identity));
        
        // 激活适配器
        objAdapter.activate();
        
    }

    /* (non-Javadoc)
     * @see IceBox.Service#stop()
     */
    @Override
    public void stop() {
        objAdapter.destroy();
    }

}
